package com.jboltai.capability.serverprocess;


import com.jboltai.util.share.AIEventThreadShareData;

public class AiServerProcessDataHandlerKit {

    public static final String key = "AiServerProcessDataHandler";
    public static void set(AiServerProcessDataHandler handler) {
        AIEventThreadShareData.set(key, handler);
    }

    public static AiServerProcessDataHandler get() {
        return AIEventThreadShareData.get(key);
    }

    public static void clear() {
        AIEventThreadShareData.remove(key);
    }

    public static void process(AiServerProcessData data) {
        if(data == null){
            throw new RuntimeException("当前线程AiServerProcessDataHandler AiServerProcessData =  null");
        }
        AiServerProcessDataHandler handler = get();
        if (handler == null) {
            throw new RuntimeException("当前线程AiServerProcessDataHandler 不存在");
        }
        handler.process(data);
    }

    public static void process(AiAppMsgType aiAppMsgType,Object data) {
        if(data == null){
            throw new RuntimeException("当前线程AiServerProcessDataHandler 要处理的data =  null");
        }
        AiServerProcessDataHandler handler = get();
        if (handler == null) {
            throw new RuntimeException("当前线程AiServerProcessDataHandler 不存在");
        }
        handler.process(new AiServerProcessData(aiAppMsgType, data));
    }

    public static void process(AiAppMsgType aiAppMsgType) {
        AiServerProcessDataHandler handler = get();
        if (handler == null) {
            throw new RuntimeException("当前线程AiServerProcessDataHandler 不存在");
        }
        handler.process(new AiServerProcessData(aiAppMsgType));
    }
}

